package Controller;

import org.apache.log4j.Logger;

public class Recovery extends Thread {

    private static Recovery recoveryObj = null;
    private static Logger logger = Logger.getLogger(Recovery.class);
    private boolean running;

    public static Recovery getInstance() {
        if (recoveryObj == null) {
            createRecoveryObj();
        }
        return recoveryObj;
    }

    private static synchronized void createRecoveryObj() {
        if (recoveryObj == null) {
            try {
                recoveryObj = new Recovery();
            } catch (Exception ex) {
                logger.fatal("exception while creating Recovery Thread", ex);
            }
        }
    }

    @Override
    public void run() {
        running = true;
        logger.debug("Recovery Thread started successfully");
        while (running) {
            
            
            try {
                Thread.sleep(30000);
            } catch (InterruptedException ex) {
                logger.fatal("Recovery Thread has been interrupted to stop");
            }
       
        }

    }

    public void shutDown() {
        running = false;
        this.interrupt();
    }
}
